Load data
data <- readRDS(list.files(data_path, pattern="FP_matrix", full.names=T))
covs <- readRDS(list.files(data_path, pattern="FP_metadata", full.names=T))
covs <- covs[, c("CERAD", "Braak", "CDR", "plaqueMean")]
protein <- "APP"
index <- match(protein, rownames(data))
input <- data[-index, ]
toPredict <- as.vector(unlist(data[index, ]))
dim(input)
Cutoff selection
r <- testAllCutoffs(exprData=input,
target=toPredict,
covs=covs,
train.split=0.7,
nfolds=5,
t=10,
path=paste0(tgcn_path),
targetName=protein,
tissueName="MSBB",
seed=1234,
cutoffs=10:1,
n=100,
m=10,
s=10,
minCor=0.3,
maxTol=3,
save=T,
overwrite=F)
r <- readRDS(paste0(tgcn_path, "/Net/APP_MSBB_TGCNs_all_cutoffs.rds"))
grid.arrange(r$selectCutoff$nHubs, r$selectCutoff$stats + theme(legend.position="bottom"))

p <- lapply(r$nets, function(cutoff) cutoff$GOenrich$plotStats)
ggarrange(p$c8 + theme(text=element_text(size=10)) + scale_y_continuous(limits=c(0,25)),
p$c9 + theme(text=element_text(size=10)) + scale_y_continuous(limits=c(0,25)),
p$c10 + theme(text=element_text(size=10)) + scale_y_continuous(limits=c(0,25)),
ncol=3, nrow=1, common.legend=T, legend="bottom")

TGCN for each cutoff
Cutoff
8
Modules size
selection
r$nets$c8$net$moduleSizeSelectionPlot

Modules
correlation

Modules
composition
DT::datatable(r$nets$c8$net$modules)
Cross tab plot

GO enrichment
stats
grid.arrange(r$nets$c8$GOenrich$plotStats, r$nets$c8$GOenrich$plotNterms, nrow=2)

DT::datatable(r$nets$c8$GOenrich$terms)
Reduced GO terms at
TGCN level
r$nets$c8$GOenrich$plotReduced

reduced_terms <- r$nets$c8$GOenrich$reducedTerms
treemapPlot(reduced_terms)

wordcloudPlot(reduced_terms, min.freq=1, colors="black")

Cell-type
enrichment

r$nets$c8$CTenrich$sigTests
Module-trait
corr
r$nets$c8$moduleTraitCorr$plot_pval

Cutoff
9
Modules size
selection
r$nets$c9$net$moduleSizeSelectionPlot

Modules
correlation

Modules
composition
DT::datatable(r$nets$c9$net$modules)
Cross tab plot

GO enrichment
stats
grid.arrange(r$nets$c9$GOenrich$plotStats, r$nets$c9$GOenrich$plotNterms, nrow=2)

DT::datatable(r$nets$c9$GOenrich$terms)
Reduced GO terms at
TGCN level
r$nets$c9$GOenrich$plotReduced

reduced_terms <- r$nets$c9$GOenrich$reducedTerms
treemapPlot(reduced_terms)

wordcloudPlot(reduced_terms, min.freq=1, colors="black")

Cell-type
enrichment

r$nets$c9$CTenrich$sigTests
Module-trait
corr
r$nets$c9$moduleTraitCorr$plot_pval

Cutoff
10
Modules size
selection
r$nets$c10$net$moduleSizeSelectionPlot

Modules
correlation

Modules
composition
DT::datatable(r$nets$c10$net$modules)
Cross tab plot

GO enrichment
stats
grid.arrange(r$nets$c10$GOenrich$plotStats, r$nets$c10$GOenrich$plotNterms, nrow=2)

DT::datatable(r$nets$c10$GOenrich$terms)
Reduced GO terms at
TGCN level
r$nets$c10$GOenrich$plotReduced

reduced_terms <- r$nets$c10$GOenrich$reducedTerms
treemapPlot(reduced_terms)

wordcloudPlot(reduced_terms, min.freq=1, colors="black")

Cell-type
enrichment

r$nets$c9$CTenrich$sigTests
Module-trait
corr
r$nets$c9$moduleTraitCorr$plot_pval

Hub gene module enrichment
go_results <- r$nets$c8$GOenrich$terms
plots <- getReducedTermsPlots(go_results, module=T)
saveRDS(plots, paste0(tgcn_path, "plots_APP_MSBB.rds"))
go_results <- r$nets$c8$GOenrich$terms
sort(table(go_results$query), decreasing=T)
##
## UCP2 ATP6AP1 ATP1B1 DHCR24 SDHC RTN1 LAMP1 HNRNPA0 OTUB2 ABCG1
## 430 68 64 44 43 35 25 9 8 8
## NEK11 NKAIN2 SART1 MCM9 STIL CAPZB PHYHIPL ZNF491 RFLNB RNF32
## 7 6 5 5 4 4 4 3 2 0
## hubs
## 0
plots <- readRDS(paste0(tgcn_path, "plots_APP_MSBB.rds"))